package com.ophiux.cs.infrastructure.compoment.basedata.mybatis.handler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataHandlerImpl implements DataHandler {
	@SuppressWarnings("rawtypes")
	private Object dataParameter = new HashMap();
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private List<Map<String, Object>> handler = new ArrayList();
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private Map<String, Object> dataView = new HashMap();

	public DataHandlerImpl(Object parameter) {
		this.dataParameter = parameter;
	}

	public DataHandler addInsert(String name, String insertData, Object parameter) {
		addHandler(name, "insertData", insertData, parameter);
		return this;
	}

	public DataHandler addUpdate(String name, String updateData, Object parameter) {
		addHandler(name, "updateData", updateData, parameter);
		return this;
	}

	public DataHandler addDelete(String name, String deleteData, Object parameter) {
		addHandler(name, "deleteData", deleteData, parameter);
		return this;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void addHandler(String name, String handlerName, String handleDataName, Object parameter) {
		Map map = new HashMap();
		map.put("name", name);
		map.put("handlerName", handlerName);
		map.put("handleDataName", handleDataName);
		if (parameter == null) {
			map.put("parameter", this.dataParameter);
		} else {
			map.put("parameter", parameter);
		}
		this.handler.add(map);
	}

	public List<Map<String, Object>> getHandler() {
		return this.handler;
	}

	public Object getDataView(String name) {
		return this.dataView.get(name);
	}

	public void setDataView(String paramString, Object paramObject) {
		this.dataView.put(paramString, dataView);
	}

}
